<?php
class Sosweb_View_Helper_PromotionGrid
{
	public function promotionGrid($promotions, $baseUrl, $sortLink, $messageText)
	{
		//header
		$html = 
  			'<table class="fullW fullH"> '.
			' <tr> '.
		  	'  <td class="promotionsCount" colspan="5"> '.
			$messageText.count($promotions).
			'  </td> '.
			' </tr> '.
			' <tr>'.
			'  <td class="promotionsCategory header2"> ';
			
		if ($sortLink != null)
		{
			$html .=
				'   <a class="promotionsHeader" href="'.$baseUrl.$sortLink.'/sort/section" title="Sortuj po kategorii."> '.
				'Kategoria'.
				'   </a> ';
		}	
		else
		{
			$html .=
				'Kategoria';
		}
		
		$html .=	
			'  </td> '.
			'  <td class="promotionsSubject header2"> ';
		
		if ($sortLink != null)
		{
			$html .=
				'   <a class="promotionsHeader" href="'.$baseUrl.$sortLink.'/sort/subject" title="Sortuj po temacie."> '.
     			'Temat '.
				'   </a> ';			
		}	
		else
		{
			$html .=
				'Temat';
		}
			
		$html .=
    		'  </td> '.
			'  <td class="promotionsViews header2"> ';
		
		if ($sortLink != null)
		{
			$html .=
				'   <a class="promotionsHeader" href="'.$baseUrl.$sortLink.'/sort/views" title="Sortuj po ilości wyświetleń."> '.
				'Wyświetleń'.
				'   </a> ';
		}	
		else
		{
			$html .=
				'Wyświetleń';
		}		
		
		$html .=
			'  </td> '.
			'  <td class="promotionsReplies header2"> ';

		if ($sortLink != null)
		{
			$html .=
				'   <a class="promotionsHeader" href="'.$baseUrl.$sortLink.'/sort/replies" title="Sortuj po ilości postów."> '.
				'Postów'.
				'   </a> ';
		}	
		else
		{
			$html .=
				'Postów';
		}		

		$html .=
			'  </td> '.
			'  <td class="promotionsRating header2"> ';

		if ($sortLink != null)
		{
			$html .=
				'   <a class="promotionsHeader" href="'.$baseUrl.$sortLink.'/sort/rating" title="Sortuj po ratingu."> '.
				'Rating'.
				'   </a> ';
		}	
		else
		{
			$html .=
				'Rating';
		}		
		
		$html .=
			'  </td> '.
			' </tr>';
		
		if (count($promotions) > 0)
		{	
			$loopCounter = 0;			
			foreach ($promotions as $key=>$value)
			{
				$html .=
					' <tr> '.
					'  <td class="promotionsCategory normal3'.($loopCounter%2 == 0 ? '' : ' dark').'"> '.
					'   <a class="promoSectionTitle" href="/forum/forumdisplay.php?fid='.$value->section_id.'" title="Przejdź do działu '.$value->section.'."> '.
					$value->section.
					'   </a> '.
					'  </td> '.					
					'  <td class="promotionsSubject normal2'.($loopCounter%2 == 0 ? '' : ' dark').'"> '.
					'   <a class="couponsTitle" href="/forum/showthread.php?tid='.$value->tid.'" title="Przejdź do promocji '.Sosweb_Util_Common_String::prepareStringFragment($value->subject).'."> '.
					Sosweb_Util_Common_String::prepareStringFragment($value->subject).
					'   </a> '.
					'  </td> '.				
					'  <td class="promotionsViews normal3'.($loopCounter%2 == 0 ? '' : ' dark').'"> '.
					$value->views.
					'  </td> '.
					'  <td class="promotionsReplies normal3'.($loopCounter%2 == 0 ? '' : ' dark').'"> '.
					$value->replies.
					'  </td> '.				
					'  <td class="promotionsRating normal3'.($loopCounter%2 == 0 ? '' : ' dark').'"> ';
					
					for ($i=0; $i<5; $i++)
					{
						if ($i < $value->rating)
						{
							$html .= '<img src="'.$baseUrl.'/public/images/star.gif" alt="Rating '.$value->rating.'" title="Rating '.$value->rating.'" />';	
						}
						else
						{
							$html .= '<img src="'.$baseUrl.'/public/images/star_zero.gif" alt="Rating '.$value->rating.'" title="Rating '.$value->rating.'" />';
						}
					}
					
					$html .=
					'  </td> '.
					' </tr> ';
				
				$loopCounter++;
			}
	
			$html .=
				'</table> ';			
		}
		else
		{
			$html .=
				 '<table> '.
				 ' <tr> '.
				 '  <td class=""> '.
				 'Brak promocji do wyświetlenia.'.
				 '  </td> '.
				 ' </tr> '.
				 '</table>';
		}
		
		return $html;
	}
}